package com.neusoft.neuiotms.dcom.repository.change.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.change.ChangePlan;
import com.neusoft.neuiotms.dcom.model.change.QChangePlan;
import com.neusoft.neuiotms.dcom.repository.change.CustomizedChangePlanRepository;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedChangePlanRepositoryImpl extends AbstractRepository implements CustomizedChangePlanRepository {

    @Override
    protected Class<?> getModelClass() {
        return ChangePlan.class;
    }

    @Override
    public ChangePlan findByWorkNum(final String workOrderNum) {
        final QChangePlan qChangePlan = QChangePlan.changePlan;
        final JPAQuery<ChangePlan> query = this.query().selectFrom(qChangePlan);
        query.where(qChangePlan.workOrderNum.eq(workOrderNum))
                .orderBy(qChangePlan.createTime.desc()).limit(1);
        return query.fetchOne();
    }

}
